package test;

import java.io.IOException;

import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.store.LockObtainFailedException;
import org.eclipse.draw2d.BorderLayout;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.FigureListener;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.ScrollPane;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.edocbase.desktop.lightweight.DesktopShell;
import com.edocbase.desktop.lightweight.widgets.FigureOwner;
import com.edocbase.desktop.plugins.mdairy.parts.SearchResultViewer;
import com.edocbase.desktop.plugins.mdiary.figures.DiaryFigure;
import com.edocbase.desktop.search.IPageList;
import com.edocbase.desktop.search.Page;
import com.edocbase.desktop.search.SearchEngine;

public class SearchResultApp {
	protected Shell shell;
	//private Label titleLabel;
	private FigureOwner body;

	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		SearchEngine.shutdown();
	}
	protected void createContents() {
		DesktopShell desktopShell = new DesktopShell(Display.getDefault());
		shell = desktopShell.getShell();
		shell.setSize(300, 600);
		shell.setText("SWT Application");
		
		body = desktopShell.getDesktopBody();
		body.setLayoutManager(new BorderLayout());
		
		//DiaryFigure f = makeFigure();
		SearchResultViewer viewer = new SearchResultViewer();
		body.add(viewer.getContainer(),BorderLayout.CENTER);
		
		
		Query query = new MatchAllDocsQuery();
		Page page = new Page(1,10);
		try {
			IPageList pageList = SearchEngine.getEngine().search(query, page);
			viewer.setInput(pageList);
		} catch (Exception e) {
			e.printStackTrace(System.err);
		} 
		
	}
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			SearchResultApp window = new SearchResultApp();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
